﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using DataLib.DBUtility;
using System.Data;


namespace DataLib.DAL
{
    public class CJOItem
    {

        /// <summary>
        /// 根据cjoID获得单张CJO单的详细信息
        /// </summary>
        /// <param name="cid">CJO单ID</param>
        /// <returns></returns>
        public Model.CJOItem GetListByCid(int cid)
        {
            Model.CJOItem model = new Model.CJOItem();
            Model.Cjo cmodel = new Model.Cjo();
            Model.LoadNum lmodel = new Model.LoadNum();
            Model.Cumtomer cummodel = new Model.Cumtomer();
            Model.VehicleRequire vmodel = new Model.VehicleRequire();
            Model.CumtomerAddress addmodel = new Model.CumtomerAddress();

            Model.Project pmodel = new Model.Project();
            Model.ProjectsRelation prmodel = new Model.ProjectsRelation();
            Model.ServerArea samodel = new Model.ServerArea();
            Model.ServerPoint spmodel = new Model.ServerPoint();

            


            cmodel = new DAL.Cjo().GetModel(cid);
            lmodel = new DAL.LoadNum().GetModel(cmodel.loadnumid);
            prmodel = new DAL.ProjectRelation().GetModel((int)cmodel.addid);
            if (prmodel != null)
            {
                spmodel = new DAL.ServerPoint().GetModel((int)prmodel.ServerPointID);
                samodel = new DAL.ServerArea().GetModel((int)spmodel.ServerAreaID);
                pmodel = new DAL.Project().GetModel((int)samodel.ProjectID);
                cummodel = new DAL.Cumtomer().GetModel((int)pmodel.CustomerID);
                addmodel = new DAL.CumtomerAddress().GetModel((int)prmodel.AddressID);
            }
            vmodel = GetVehicleRequireByCid(cid);




            model.istyz = cmodel.istyz;
            model.totalWeight = lmodel.totalWeight;
            model.finishWeight = lmodel.finishWeight;
            model.Saleman = cmodel.sealman_create;
            model.cjoid = cmodel.id;
            model.cjono = cmodel.cjono;
            model.Addressid = addmodel.id;
            model.Belogcity = addmodel.City;
            model.belongArea = lmodel.belongarea;
            model.Graphicy = lmodel.Rubbisharea;
            model.predictweight = (decimal)cmodel.predictweight;
            model.CjoColldate = cmodel.cjocolldate;

            model.customercode = cmodel.customercode;
            model.customerid = cummodel.id;
            model.companyname = cmodel.customername;
            model.collectdate = (DateTime)cmodel.cjocolldate;
            model.createtime = cmodel.createtime;
            model.islocal = cmodel.islocal;
            model.maternrequire = vmodel.maternrequire;
            model.numberestimate = vmodel.numberestimate;
            model.other = vmodel.other;
            model.othercost = vmodel.othercost;
            model.peculiarrequire = vmodel.peculiarrequire;
            model.samplingrequire = vmodel.samplingrequire;

            model.tools = vmodel.tools;
            model.vehichlerequireid = vmodel.id;
            model.vehiclecount = vmodel.vehiclecount;
            model.workercount = vmodel.workercount;
            model.loadnumid = lmodel.id;
            model.loadnumno = lmodel.loadnum;
            model.cjonwt = GetCjoNwt((int)model.cjoid);
            model.cjoremark = cmodel.cjoremark;
          

            model.status = (int)cmodel.status;

            if (prmodel != null)
            {
                model.CjoAddId = (int)prmodel.AddressID;
                model.goodsdesc = cmodel.goodsdesc;
                model.Graphicy = cmodel.graphiccity;
                model.Belogcity = cmodel.belogcity;
                model.RubbType = cmodel.rubbType;
                model.cjolinkman = cmodel.cjolinkman;
                model.cjophone = cmodel.cjophone;
                model.cjoaddinfo = cmodel.cjoadd;

                model.proejctid = pmodel.ProjectID;
                model.pronum = pmodel.ProjectNum;
                model.proname = pmodel.ProjectName;
                model.serverareaid = samodel.id;
                model.serverpointid = spmodel.id;
                model.prorelid = prmodel.id;
                model.serverareaname = samodel.AreaName;
                model.serverpointname = spmodel.ServerPointName;
                model.cjocreatemanusername = spmodel.CjopersonUserName;
                model.cjocreatemantruename = spmodel.CjopersonTrueName;
                model.cjoviewmanusername = spmodel.LookSalesmanUserName;
                model.cjoviewmantruename = spmodel.LookSalesmanTrueName;
                model.sppowertruename = spmodel.PowerpersonTrueName;
                model.sppowerusername = spmodel.PowerpersonUserName;
                char[] splitchar = { '/', '@' };
                if (spmodel.Cjoperson_show.Length > 6)
                {
                    string[] arr = spmodel.Cjoperson_show.Split(splitchar);
                    model.cjoshowmanusername = arr[0];
                    model.cjoshowmantruename = arr[1];
                }
                model.cjopowerusername = spmodel.PowerpersonUserName;
                model.cjopowertruename = spmodel.PowerpersonTrueName;

                Accounts.Bus.User su = null;

                if (model.Saleman != null && model.Saleman.Trim() != "")
                {
                    su = new Accounts.Bus.User(model.Saleman);
                }
                else
                {
                    string uname = "";
                    if (spmodel.Cjoperson_show.IndexOf("/") > 0)
                    {
                        uname = spmodel.Cjoperson_show.Substring(0, spmodel.Cjoperson_show.IndexOf("/") );
                    }
                    else if(spmodel.Cjoperson_show.IndexOf("@") > 0)
                    {
                        uname = spmodel.Cjoperson_show.Substring(0, spmodel.Cjoperson_show.IndexOf("@") );
                    }
                    su = new Accounts.Bus.User(uname);
                }
                
                if (su != null)
                    model.sealmanphone = su.Phone;
              
            }
            return model;
        }

        /// <summary>
        /// 取得cjo单的净重
        /// </summary>
        /// <param name="cjoid"></param>
        /// <returns></returns>
        private decimal GetCjoNwt(int cjoid)
        {
            string strsql = "select sum(nwt) from barcode where (status=1 or status=2) and cjoid=" + cjoid.ToString();
            DataTable dt = DbHelperSQL.Query(strsql).Tables[0];
            if (dt != null && dt.Rows.Count > 0 && dt.Rows[0][0] != null && dt.Rows[0][0].ToString().Trim() != "")
                return decimal.Parse(dt.Rows[0][0].ToString().Trim());
            else
                return 0;
        }


        /// <summary>
        /// 根据cjo单号获取收集数据编号
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        private Model.VehicleRequire GetVehicleRequireByCid(int cid)
        {
            Model.VehicleRequire model = new Model.VehicleRequire();
            DAL.VehicleRequire dal = new VehicleRequire();
            DataTable dt = new DataTable();
            dt = dal.GetList("cjoid=" + cid).Tables[0];
            DataRow dr = dt.NewRow();
            if (dt.Rows.Count>0)
            {
                dr = dt.Rows[0];
            }
            model = dal.DataRowToModel(dr);
            return model;
        }

 
        /// <summary>
        /// 根据CJO表的where语句取得CJOItem列表
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public List<DataLib.Model.CJOItem> GetCJOList(string where)
        {
            List<DataLib.Model.CJOItem> modelist = new List<Model.CJOItem>();
            DataTable dt = new DataTable();
            Cjo dal = new Cjo();
            dt =dal.GetList(where).Tables[0];
            
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataLib.Model.CJOItem model = new Model.CJOItem();
                model = GetListByCid(int.Parse(dt.Rows[i]["id"].ToString()));
                modelist.Add(model);
            }
            return modelist;
        }

        public List<DataLib.Model.CJOItem> GetCJOListByLoadWhere(string where)
        {
            List<DataLib.Model.CJOItem> modellist = new List<Model.CJOItem>();
            DataTable dt = new DataTable();
            return modellist;
        }

        /// <summary>
        /// 可以联合查询的数据集，关联LoadNum l，VehicleRequire v，Cumtomer cum，CumtomerAddress cumadd，Cjo c
        /// </summary>
        /// <param name="where">条件字段需带上表名</param>
        /// <returns></returns>
        public DataTable GetCJOitemTable(string where)
        {
            DataTable dt = new DataTable();
            SqlParameter[] sqlparameter ={
                new SqlParameter("@where",SqlDbType.VarChar,255)
             };
            sqlparameter[0].Value = where;
            SqlDataReader dr = DbHelperSQL.RunProcedure("Ewts_GetCJOItemByWhere", sqlparameter);
            dt.Load(dr);
            dr.Close();
            return dt;
        }

        /// <summary>
        /// 单个对象赋值
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        public Model.CJOItem DataRowToCjoItem(DataRow dr)
        {
            Model.CJOItem model = new Model.CJOItem();
            model.loadnumid = int.Parse(dr["loadnumid"].ToString());
            model.loadnumno = dr["loadnumno"].ToString();
            model.RubbType = dr["RubbType"].ToString();
            model.belongArea = dr["belongarea"].ToString();
            model.customerid = int.Parse(dr["customerid"].ToString());
            model.collectdate = DateTime.Parse(dr["collectdate"].ToString());
            model.goodsInfo = dr["goodsInfo"].ToString();
            model.totalWeight = decimal.Parse(dr["totalWeight"].ToString());
            model.finishWeight = decimal.Parse(dr["finishWeight"].ToString());
            model.LoadStatus = int.Parse(dr["lstatus"].ToString());
            model.Saleman = dr["Saleman"].ToString();

            model.cjoid = int.Parse(dr["cjoid"].ToString());
            model.cjono = dr["cjono"].ToString();
            model.CjoAddId = int.Parse(dr["CjoAddId"].ToString());
            model.CjoColldate = DateTime.Parse(dr["CjoColldate"].ToString());
            model.cjonwt = decimal.Parse(dr["cjonwt"].ToString());
            model.goodsdesc = dr["goodsdesc"].ToString();
            model.Graphicy = dr["Graphicy"].ToString();
            model.islocal = Boolean.Parse(dr["islocal"].ToString());
            model.operman = dr["operman"].ToString();
            model.RubbType = dr["RubbType"].ToString();
            model.status = int.Parse(dr["status"].ToString());

            model.vehichlerequireid = int.Parse(dr[""].ToString());
            return model;
        }

        /// <summary>
        /// 新增一张CJO，或者修改
        /// </summary>
        /// <param name="lModel">如果是从原有Load新开CJO，则LoadID为零</param>
        /// <param name="cModel">CJO</param>
        /// <param name="vModel"></param>
        /// <returns></returns>
        public int InsertCjoItem(Model.LoadNum lModel,Model.Cjo cModel, Model.VehicleRequire vModel)
        {
            int rows;


            SqlParameter[] sqlparameter ={
                 new SqlParameter("@loadid", SqlDbType.Int)
                ,new SqlParameter("@loadnum",SqlDbType.VarChar,12)
                ,new SqlParameter("@addressid",SqlDbType.Int)
                ,new SqlParameter("@Rubbisharea",SqlDbType.NVarChar,10)
                ,new SqlParameter("@belongarea",SqlDbType.NVarChar,10)
                ,new SqlParameter("@customerid",SqlDbType.Int)
                ,new SqlParameter("@collectdate",SqlDbType.DateTime)
                ,new SqlParameter("@goodsInfo",SqlDbType.NVarChar,3500)
                ,new SqlParameter("@totalWeight",SqlDbType.Decimal)
                ,new SqlParameter("@finishWeight",SqlDbType.Decimal)
                ,new SqlParameter("@lstatus",SqlDbType.Int)
                ,new SqlParameter("@saleman",SqlDbType.NVarChar,12)
                ,new SqlParameter("@RubbishType",SqlDbType.NVarChar,200) 
               ,new SqlParameter("@Memo",SqlDbType.NVarChar,200)

                ,new SqlParameter("@cjono",SqlDbType.NVarChar,20)
                ,new SqlParameter("@createtime",SqlDbType.DateTime)
                ,new SqlParameter("@islocal",SqlDbType.BigInt)
                ,new SqlParameter("@customercode",SqlDbType.NVarChar,20)
                ,new SqlParameter("@customername",SqlDbType.NVarChar,50)
                ,new SqlParameter("@operman",SqlDbType.NVarChar,20)
                ,new SqlParameter("@predictweight",SqlDbType.Decimal)
                ,new SqlParameter("@cjocolldate",SqlDbType.DateTime)
                ,new SqlParameter("@addid",SqlDbType.Int)
                ,new SqlParameter("@goodsdesc",SqlDbType.NVarChar,3500)
                ,new SqlParameter("@graphiccity",SqlDbType.NVarChar,20)
                ,new SqlParameter("@belogcity",SqlDbType.NVarChar,20)
                ,new SqlParameter("@rubbType",SqlDbType.NVarChar,200) //废弃物类型长度20改为200  20130419 梁玲
                ,new SqlParameter("@cstatus",SqlDbType.Int)

                ,new SqlParameter("@workercount",SqlDbType.NVarChar,20)
                ,new SqlParameter("@vehiclecount",SqlDbType.Int)
                ,new SqlParameter("@othercost",SqlDbType.Decimal)
                ,new SqlParameter("@other",SqlDbType.NVarChar,200)
                ,new SqlParameter("@tools",SqlDbType.NVarChar,200)
                ,new SqlParameter("@clearingform",SqlDbType.NVarChar,200)
                ,new SqlParameter("@numberestimate",SqlDbType.Float)
                ,new SqlParameter("@maternrequire",SqlDbType.NVarChar,200)
                ,new SqlParameter("@samplingrequire",SqlDbType.NVarChar,200)
                ,new SqlParameter("@peculiarrequire",SqlDbType.NVarChar,200)
                ,new SqlParameter("@otherrequire",SqlDbType.NVarChar,200)
                ,new SqlParameter("@othervrequire",SqlDbType.NVarChar,200)
                ,new SqlParameter("@cjoAdd",SqlDbType.NVarChar,500)
                ,new SqlParameter("@cjolinkman",SqlDbType.NVarChar,20)
                ,new SqlParameter("@cjophone",SqlDbType.NVarChar,50)
                ,new SqlParameter("@sealman_show",SqlDbType.VarChar,20)
                ,new SqlParameter("@sealman_create",SqlDbType.VarChar,20)
                ,new SqlParameter("@sealman_auth",SqlDbType.VarChar,20)
                ,new SqlParameter("@sealman_view",SqlDbType.VarChar,200)

                ,new SqlParameter("@cjoid",SqlDbType.Int)
                ,new SqlParameter("@vrid",SqlDbType.Int)
                ,new SqlParameter("@istyz",SqlDbType.VarChar,200)
                ,new SqlParameter("@busstype",SqlDbType.VarChar,20)
                ,new SqlParameter("@cjoremark",SqlDbType.VarChar,200)
                };
            sqlparameter[0].Value = lModel.id;
            sqlparameter[1].Value=lModel.loadnum;
            sqlparameter[2].Value = cModel.addid;
            sqlparameter[3].Value = lModel.Rubbisharea;
            sqlparameter[4].Value = lModel.belongarea;
            sqlparameter[5].Value = lModel.customerid;
            sqlparameter[6].Value = cModel.cjocolldate;
            sqlparameter[7].Value = lModel.goodsInfo;
            sqlparameter[8].Value = lModel.totalWeight;
            sqlparameter[9].Value = lModel.finishWeight;
            sqlparameter[10].Value = 1;
            sqlparameter[11].Value = lModel.saleman;
            sqlparameter[12].Value = lModel.RubbishType;
            sqlparameter[13].Value = lModel.Memo;

            sqlparameter[14].Value = cModel.cjono;
            sqlparameter[15].Value = cModel.createtime;
            sqlparameter[16].Value = cModel.islocal;
            sqlparameter[17].Value = cModel.customercode;
            sqlparameter[18].Value = cModel.customername;
            sqlparameter[19].Value = cModel.operman;
            sqlparameter[20].Value = cModel.predictweight;
            sqlparameter[21].Value = cModel.cjocolldate;
            sqlparameter[22].Value = cModel.addid;
            sqlparameter[23].Value = cModel.goodsdesc;
            sqlparameter[24].Value = cModel.graphiccity;
            sqlparameter[25].Value = cModel.belogcity;
            sqlparameter[26].Value = cModel.rubbType;
            sqlparameter[27].Value = cModel.status;

            sqlparameter[28].Value = vModel.workercount;
            sqlparameter[29].Value = vModel.vehiclecount;
            sqlparameter[30].Value = vModel.othercost;
            sqlparameter[31].Value = vModel.other;
            sqlparameter[32].Value = vModel.tools;
            sqlparameter[33].Value = vModel.clearingform;
            sqlparameter[34].Value = vModel.numberestimate;
            sqlparameter[35].Value = vModel.maternrequire;
            sqlparameter[36].Value = vModel.samplingrequire;
            sqlparameter[37].Value = vModel.peculiarrequire;
            sqlparameter[38].Value = vModel.otherrequire;
            sqlparameter[39].Value = vModel.othervrequire;

            sqlparameter[40].Value = cModel.cjoadd;
            sqlparameter[41].Value = cModel.cjolinkman;
            sqlparameter[42].Value = cModel.cjophone;

            Model.ServerPoint spmodel = new Model.ServerPoint();
            ServerPoint spdal = new ServerPoint();
            Model.ProjectsRelation prmodel = new ProjectRelation().GetModel((int)cModel.addid);
            if (prmodel != null)
            {
                spmodel = spdal.GetModel((int)prmodel.ServerPointID);
                sqlparameter[43].Value = spmodel.Cjoperson_show;
                sqlparameter[44].Value = spmodel.CjopersonUserName;
                sqlparameter[45].Value = spmodel.PowerpersonUserName;
                sqlparameter[46].Value = spmodel.LookSalesmanUserName;
            }
            sqlparameter[47].Value = cModel.id;
            sqlparameter[48].Value = vModel.id;
            sqlparameter[49].Value = cModel.istyz;
            sqlparameter[50].Value = cModel.bussinesstype;
            sqlparameter[51].Value = cModel.cjoremark;

            rows = DbHelperSQL.RunProcedure("EWMS_CJO_Insert", sqlparameter,out rows);
            return rows;
   
        }

        /// <summary>
        /// 修改一张CJO，
        /// </summary>
        /// <param name="lModel">LoadNum</param>
        /// <param name="cModel">CJO</param>
        /// <param name="vModel"></param>
        /// <returns></returns>
        public int UpdateCjoItem(Model.LoadNum lModel, Model.Cjo cModel, Model.VehicleRequire vModel)
        {
            int rows;


            SqlParameter[] sqlparameter ={
                 new SqlParameter("@loadid", SqlDbType.Int)
                ,new SqlParameter("@loadnum",SqlDbType.VarChar,12)
                ,new SqlParameter("@addressid",SqlDbType.Int)
                ,new SqlParameter("@Rubbisharea",SqlDbType.NVarChar,10)
                ,new SqlParameter("@belongarea",SqlDbType.NVarChar,10)
                ,new SqlParameter("@customerid",SqlDbType.Int)
                ,new SqlParameter("@collectdate",SqlDbType.DateTime)
                ,new SqlParameter("@goodsInfo",SqlDbType.NVarChar,100)
                ,new SqlParameter("@totalWeight",SqlDbType.Decimal)
                ,new SqlParameter("@finishWeight",SqlDbType.Decimal)
                ,new SqlParameter("@lstatus",SqlDbType.Int)
                ,new SqlParameter("@saleman",SqlDbType.NVarChar,12)
                ,new SqlParameter("@RubbishType",SqlDbType.NVarChar,200)
               ,new SqlParameter("@Memo",SqlDbType.NVarChar,200) 

                ,new SqlParameter("@cjoid",SqlDbType.Int)
                ,new SqlParameter("@cjono",SqlDbType.NVarChar,20)
                ,new SqlParameter("@createtime",SqlDbType.DateTime)
                ,new SqlParameter("@islocal",SqlDbType.BigInt)
                ,new SqlParameter("@customercode",SqlDbType.NVarChar,20)
                ,new SqlParameter("@customername",SqlDbType.NVarChar,50)
                ,new SqlParameter("@operman",SqlDbType.NVarChar,20)
                ,new SqlParameter("@predictweight",SqlDbType.Decimal)
                ,new SqlParameter("@cjocolldate",SqlDbType.DateTime)
                ,new SqlParameter("@addid",SqlDbType.Int)
                ,new SqlParameter("@goodsdesc",SqlDbType.NVarChar,50)
                ,new SqlParameter("@graphiccity",SqlDbType.NVarChar,20)
                ,new SqlParameter("@belogcity",SqlDbType.NVarChar,20)
                ,new SqlParameter("@rubbType",SqlDbType.NVarChar,200) 
                ,new SqlParameter("@cstatus",SqlDbType.Int)

                ,new SqlParameter("@vehicleid",SqlDbType.Int)
                ,new SqlParameter("@workercount",SqlDbType.NVarChar,20)
                ,new SqlParameter("@vehiclecount",SqlDbType.Int)
                ,new SqlParameter("@othercost",SqlDbType.Decimal)
                ,new SqlParameter("@other",SqlDbType.NVarChar,200)
                ,new SqlParameter("@tools",SqlDbType.NVarChar,200)
                ,new SqlParameter("@clearingform",SqlDbType.NVarChar,200)
                ,new SqlParameter("@numberestimate",SqlDbType.Float)
                ,new SqlParameter("@maternrequire",SqlDbType.NVarChar,200)
                ,new SqlParameter("@samplingrequire",SqlDbType.NVarChar,200)
                ,new SqlParameter("@peculiarrequire",SqlDbType.NVarChar,200)
                ,new SqlParameter("@otherrequire",SqlDbType.NVarChar,200)
                ,new SqlParameter("@othervrequire",SqlDbType.NVarChar,200)
 
                ,new SqlParameter("@cjoAdd",SqlDbType.NVarChar,500)
                ,new SqlParameter("@cjolinkman",SqlDbType.NVarChar,20)
                ,new SqlParameter("@cjophone",SqlDbType.NVarChar,20)
                ,new SqlParameter("@istyz",SqlDbType.VarChar,200)
                ,new SqlParameter("@busstype",SqlDbType.VarChar,20)
                ,new SqlParameter("@cjoremark",SqlDbType.VarChar,200)
             };
            sqlparameter[0].Value = lModel.id;
            sqlparameter[1].Value = lModel.loadnum;
            sqlparameter[2].Value = lModel.addressid;
            sqlparameter[3].Value = lModel.Rubbisharea;
            sqlparameter[4].Value = lModel.belongarea;
            sqlparameter[5].Value = lModel.customerid;
            sqlparameter[6].Value = cModel.cjocolldate;
            sqlparameter[7].Value = lModel.goodsInfo;
            sqlparameter[8].Value = lModel.totalWeight;
            sqlparameter[9].Value = lModel.finishWeight;
            sqlparameter[10].Value = lModel.status;
            sqlparameter[11].Value = lModel.saleman;
            sqlparameter[12].Value = lModel.RubbishType;
            sqlparameter[13].Value = lModel.Memo;

            sqlparameter[14].Value = cModel.id;
            sqlparameter[15].Value = cModel.cjono;
            sqlparameter[16].Value = cModel.createtime;
            sqlparameter[17].Value = cModel.islocal;
            sqlparameter[18].Value = cModel.customercode;
            sqlparameter[19].Value = cModel.customername;
            sqlparameter[20].Value = cModel.operman;
            sqlparameter[21].Value = cModel.predictweight;
            sqlparameter[22].Value = cModel.cjocolldate;
            sqlparameter[23].Value = cModel.addid;
            sqlparameter[24].Value = cModel.goodsdesc;
            sqlparameter[25].Value = cModel.graphiccity;
            sqlparameter[26].Value = cModel.belogcity;
            sqlparameter[27].Value = cModel.rubbType;
            sqlparameter[28].Value = cModel.status;

            sqlparameter[29].Value = vModel.id;
            sqlparameter[30].Value = vModel.workercount;
            sqlparameter[31].Value = vModel.vehiclecount;
            sqlparameter[32].Value = vModel.othercost;
            sqlparameter[33].Value = vModel.other;
            sqlparameter[34].Value = vModel.tools;
            sqlparameter[35].Value = vModel.clearingform;
            sqlparameter[36].Value = vModel.numberestimate;
            sqlparameter[37].Value = vModel.maternrequire;
            sqlparameter[38].Value = vModel.samplingrequire;
            sqlparameter[39].Value = vModel.peculiarrequire;
            sqlparameter[40].Value = vModel.otherrequire;
            sqlparameter[41].Value = vModel.othervrequire;

            sqlparameter[42].Value = cModel.cjoadd;
            sqlparameter[43].Value = cModel.cjolinkman;
            sqlparameter[44].Value = cModel.cjophone;
            sqlparameter[45].Value = cModel.istyz;
            sqlparameter[46].Value = cModel.bussinesstype;
            sqlparameter[47].Value = cModel.cjoremark;

            rows = DbHelperSQL.RunProcedure("EWMS_CJO_Update", sqlparameter, out rows);
            return rows;

        }

        /// <summary>
        /// 返回ＣＪＯ的详细列表
        /// </summary>
        /// <returns></returns>
        public DataTable GetCJOitemDt(string LoadNum, string cjono, string Cum, string belongcity, string graphicity, string saleman, string loadstatus, string cjostatus, string StartDate, string EndDate,string isLocal)
        {
            DataTable dt = new DataTable();
            SqlParameter[] sqlparameter ={
                new SqlParameter("@LoadNum",SqlDbType.VarChar,15),
                new SqlParameter("@CJON0",SqlDbType.VarChar,15),
                new SqlParameter("@Cum",SqlDbType.VarChar,15),
                new SqlParameter("@BelongCity",SqlDbType.VarChar,10),
                new SqlParameter("@GraphicCity",SqlDbType.VarChar,15),
                new SqlParameter("@Saleman",SqlDbType.VarChar,15),
                new SqlParameter("@LoadStatus",SqlDbType.VarChar,2),
                new SqlParameter("@CJOStatus",SqlDbType.VarChar,2),
                new SqlParameter("@StartDate",SqlDbType.DateTime),
                new SqlParameter("@EndDate",SqlDbType.DateTime),
                new SqlParameter("@isLocal",SqlDbType.VarChar,2)
             };
            sqlparameter[0].Value = LoadNum;
            sqlparameter[1].Value = cjono;
            sqlparameter[2].Value = Cum;
            sqlparameter[3].Value = belongcity;
            sqlparameter[4].Value = graphicity;
            sqlparameter[5].Value = saleman;
            sqlparameter[6].Value = loadstatus;
            sqlparameter[7].Value = cjostatus;
            if (StartDate != "" && EndDate != "")
            {
                sqlparameter[8].Value = StartDate;
                sqlparameter[9].Value = EndDate;
            }
            sqlparameter[10].Value = isLocal;

            SqlDataReader dr = DbHelperSQL.RunProcedure("EWMS_GetCJOItem", sqlparameter);
            dt.Load(dr);
            dr.Close();
            return dt;
        }

        /// <summary>
        /// 返回LoadStatus进程列表
        /// </summary>
        /// <param name="city">处理地</param>
        /// <returns></returns>
        public DataTable GetLoadStatusList(string city)
        {
            DataTable dt = new DataTable();
            SqlParameter[] sqlparameter ={
                new SqlParameter("@city",SqlDbType.VarChar,20)
             };
            sqlparameter[0].Value = city;
            SqlDataReader dr = DbHelperSQL.RunProcedure("EWMS_GetLoadStatusList", sqlparameter);
            dt.Load(dr);
            dr.Close();
            return dt;
        }

        /// <summary>
        /// 返回LoadStatus进程列表
        /// </summary>
        /// <param name="city">处理地</param>
        /// <returns></returns>
        public DataTable GetLoadStatusList(string uerName, int currpage, int length, out int totalRecord, string search, string city, string order_column, string order_dir, string uname)
        {
            totalRecord = 0;
            DataTable dt = new DataTable();
            SqlParameter[] sqlparameter ={
                new SqlParameter("@currpage",SqlDbType.Int),
                new SqlParameter("@Length",SqlDbType.Int),
                new SqlParameter("@totalcount",SqlDbType.Int),
                new SqlParameter("@search",SqlDbType.VarChar,100),
                new SqlParameter("@city",SqlDbType.VarChar,50),
                new SqlParameter("@order_column",SqlDbType.VarChar,20),
                new SqlParameter("@order_dir",SqlDbType.VarChar,20),
                new SqlParameter("@uname",SqlDbType.VarChar,20)

             };
            sqlparameter[0].Value = currpage;
            sqlparameter[1].Value = length;
            sqlparameter[2].Value = totalRecord;
            sqlparameter[2].Direction = ParameterDirection.Output;
            sqlparameter[3].Value = search;
            sqlparameter[4].Value = city;
            sqlparameter[5].Value = order_column;
            sqlparameter[6].Value = order_dir;
            sqlparameter[7].Value = uname;
            SqlDataReader dr = DbHelperSQL.RunProcedure("EWMS_GetLoadStatusList_Store", sqlparameter);
            dt.Load(dr);
            totalRecord = Convert.ToInt32(sqlparameter[2].Value);
            dr.Close();
            return dt;
        }

        /// <summary>
        /// 返回CJO列表，含项目信息
        /// </summary>
        /// <param name="city">处理地</param>
        /// <returns></returns>
        public DataTable GetList_PROCJO(string bcity, string gcity, int islocal, int cstatus)
        {
            DataTable dt = new DataTable();
            SqlParameter[] sqlparameter ={
                new SqlParameter("@bcity",SqlDbType.VarChar,20)
                ,new SqlParameter("@gcity",SqlDbType.VarChar,20)
                ,new SqlParameter("@islocal",SqlDbType.Int)
                ,new SqlParameter("@cstatus",SqlDbType.Int)
            };
            sqlparameter[0].Value = bcity;
            sqlparameter[1].Value = gcity;
            sqlparameter[2].Value = islocal;
            sqlparameter[3].Value = cstatus;
            SqlDataReader dr = DbHelperSQL.RunProcedure("EWMS_GETCJO_PRO", sqlparameter);
            dt.Load(dr);
            dr.Close();
            return dt;
        }

        /// <summary>
        /// 获取退动直销列表
        /// </summary>
        /// <param name="city">处理地</param>
        /// <returns></returns>
        public DataTable GetDirectSellList(string city)
        {
            DataTable dt = new DataTable();
            SqlParameter[] sqlparameter ={
                new SqlParameter("@city",SqlDbType.VarChar,20)
            
            };
            sqlparameter[0].Value = city;

            SqlDataReader dr = DbHelperSQL.RunProcedure("EWMS_GetDirectSell", sqlparameter);
            dt.Load(dr);
            dr.Close();
            return dt;
        }

        public DataTable UpdateLtrTab(int? id,string idtype) {
            //[EWMS_UpdateLTR_CJO]
            DataTable dt = new DataTable();
            SqlParameter[] sqlparameter ={
                new SqlParameter("@id",SqlDbType.Int)
                ,new SqlParameter("@idtype",SqlDbType.VarChar,20)
            
            };
            sqlparameter[0].Value = id;
            sqlparameter[1].Value = idtype;
            SqlDataReader dr = DbHelperSQL.RunProcedure("EWMS_UpdateLTR_CJO", sqlparameter);
            dt.Load(dr);
            dr.Close();
            return dt;
        }

        /// <summary>
        /// 取得待授权列表
        /// </summary>
        /// <param name="uerName"></param>
        /// <returns></returns>
        public DataTable getAuthList(int currpage, int length, out int totalRecord, string search, string city, string order_column, string order_dir, string username)
        {
            totalRecord = 0;
            DataTable dt = new DataTable();
            SqlParameter[] sqlparameter ={
                new SqlParameter("@currpage",SqlDbType.Int),
                new SqlParameter("@Length",SqlDbType.Int),
                new SqlParameter("@totalcount",SqlDbType.Int),
                new SqlParameter("@search",SqlDbType.VarChar,100),
                new SqlParameter("@city",SqlDbType.VarChar,50),
                new SqlParameter("@order_column",SqlDbType.VarChar,20),
                new SqlParameter("@order_dir",SqlDbType.VarChar,20),
                new SqlParameter("@username",SqlDbType.VarChar,20)

             };
            sqlparameter[0].Value = currpage;
            sqlparameter[1].Value = length;
            sqlparameter[2].Value = totalRecord;
            sqlparameter[2].Direction = ParameterDirection.Output;
            sqlparameter[3].Value = search;
            sqlparameter[4].Value = city;
            sqlparameter[5].Value = order_column;
            sqlparameter[6].Value = order_dir;
            sqlparameter[7].Value = username;
            SqlDataReader dr = DbHelperSQL.RunProcedure("EWMS_GetAuthList", sqlparameter);
            dt.Load(dr);
            totalRecord = Convert.ToInt32(sqlparameter[2].Value);
            dr.Close();
            return dt;
             
        }


        /// <summary>
        /// 2016年12月27日 21:30:49
        /// Redplum
        /// 待称重分页 异步调用
        /// </summary>
        /// <param name="bcity"></param>
        /// <param name="gcity"></param>
        /// <param name="currpage"></param>
        /// <param name="length"></param>
        /// <param name="totalRecord"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public DataTable GetWatiInsByStore(int currpage, int length, out int totalRecord, string search, string bcity, string gcity, string order_column, string order_dir,string user)
        {
            totalRecord = 0;
            DataTable dt = new DataTable();
            SqlParameter[] sqlparameter ={
                new SqlParameter("@currpage",SqlDbType.Int),
                new SqlParameter("@Length",SqlDbType.Int),
                new SqlParameter("@totalcount",SqlDbType.Int),
                new SqlParameter("@search",SqlDbType.VarChar,100),
                new SqlParameter("@bcity",SqlDbType.VarChar,50),
                new SqlParameter("@gcity",SqlDbType.VarChar,50),
                new SqlParameter("@order_column",SqlDbType.VarChar,20),
                new SqlParameter("@order_dir",SqlDbType.VarChar,20)
             };
            sqlparameter[0].Value = currpage;
            sqlparameter[1].Value = length;
            sqlparameter[2].Value = totalRecord;
            sqlparameter[2].Direction = ParameterDirection.Output;
            sqlparameter[3].Value = search;
            sqlparameter[4].Value = bcity;
            sqlparameter[5].Value = gcity;
            sqlparameter[6].Value = order_column;
            sqlparameter[7].Value = order_dir;
            SqlDataReader dr = DbHelperSQL.RunProcedure("EWMS_WRLLIST", sqlparameter);
            dt.Load(dr);
            totalRecord = Convert.ToInt32(sqlparameter[2].Value);
            dr.Close();
            return dt;

        }
    }
}
